//
//  HKUserInfoCell.m
//  HKTimeKitApp
//
//  Created by huzhaoke1 on 2023/5/10.
//

#import "HKUserInfoCell.h"
#import "HKCommonDefine.h"
#import "UIView+properties.h"
#import "HKFontHelper.h"
#import "UILabel+create.h"
#import <Masonry/Masonry.h>

static const CGFloat kKSLeft = 24.f;

@interface HKUserInfoCell ()

@property (nonatomic , strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *userInfoLab;
@property (nonatomic, strong) UIView *lineView;

@end

@implementation HKUserInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.titleLab];
        [self.contentView addSubview:self.userInfoLab];
        [self.contentView addSubview:self.lineView];
        
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kKSLeft);
            make.centerY.mas_equalTo(self.contentView);
        }];
        [self.userInfoLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView).offset(-kKSLeft);
            make.centerY.mas_equalTo(self.contentView);
        }];
        [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kKSLeft);
            make.right.mas_equalTo(self.contentView).offset(-kKSLeft);
            make.height.mas_equalTo(1);
            make.bottom.mas_equalTo(self.contentView);
        }];
    }
    return self;
}

+ (CGFloat)cellHeightWithContent:(id)content {
    return 48;
}

- (void)updateContent:(id)content {
    HKUserInfoCellViewModel *viewModel = KSSAFE_CAST(content, HKUserInfoCellViewModel);
    self.titleLab.text = viewModel.title;
    self.userInfoLab.text = viewModel.userInfo;
}

#pragma mark - getter & setter
- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel labelWithFont:[HKFontHelper appcnFontWithSize:16.f]
                                    bgColor:nil
                                  textColor:UIColorFromRGB(0x828282) textAligment:NSTextAlignmentLeft];
    }
    return _titleLab;
}

- (UILabel *)userInfoLab {
    if (!_userInfoLab) {
        _userInfoLab = [UILabel labelWithFont:[HKFontHelper appcnFontWithSize:16.f]
                                    bgColor:nil
                                  textColor:UIColorFromRGB(0x333333) textAligment:NSTextAlignmentRight];
    }
    return _userInfoLab;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = [UIColorFromRGB(0xb8b8b9) colorWithAlphaComponent:0.11];
    }
    return _lineView;
}

@end


@implementation HKUserInfoCellViewModel

@end
